import { Effect, ImmerReducer, Reducer, Subscription } from 'umi';
import { getAbout } from "@/services";

export interface IndexModelState {
    name: string;
    page: number;
}

export interface IndexModelType {
    namespace: 'about';
    state: IndexModelState;
    effects: {
        getAbout: Effect;
    };
    reducers: {
        save: Reducer<IndexModelState>;
        // 启用 immer 之后
        // save: ImmerReducer<IndexModelState>;
    };
    subscriptions?: { setup: Subscription };
}

const AboutModel: IndexModelType = {
    namespace: 'about',

    state: {
        name: '',
        page: 1,
    },

    effects: {
        *getAbout({ payload }, { call, put }) {
            let res = yield call(getAbout)
            yield put({
                type: "save",
                payload: {
                    name: res
                }
            })
        },

    },
    reducers: {
        save(state, action) {
            return {
                ...state,
                ...action.payload,
            };
        },
        // 启用 immer 之后
        // save(state, action) {
        //   state.name = action.payload;
        // },
    },

};

export default AboutModel;